<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<%@include file="connection.jsp"%>
<%
 
	String userid = (String) session.getAttribute("userid");

    if (userid == null)
    {
       response.sendRedirect("login.jsp");
    }
    
    //String userName = (String) session.getAttribute("name");
	String pId = request.getParameter("pid");
    Connection c = getConnection(session);
    Statement s = c.createStatement();


	String LastName = "";
	String FirstName = "";
	String Address = "";
	String City = "";
	String State = "";
	String Zip = "";
	String DOB = "";
	String Sex = "";
	String SSN = "";
	String HomePhone = "";
	String MaritalStatus = "";
	String PatientCondition = "";
	
	ResultSet rs = s.executeQuery("select * from tblpatientinformation where patientID = '"+pId+"'");
	
	if(rs.first()){	
		
		//patientID = rs.getString("patientID");
		LastName = rs.getString("LastName");
		FirstName = rs.getString("FirstName");
		Address = rs.getString("Address");
		City = rs.getString("City");
		State = rs.getString("State");
		Zip = rs.getString("Zip");
		DOB = rs.getString("DOB");
		Sex = rs.getString("Sex");
		SSN = rs.getString("SSN");
		HomePhone = rs.getString("HomePhone");
		MaritalStatus = rs.getString("MaritalStatus");
		PatientCondition = rs.getString("PatientCondition");	
}




%>
<html>
    <head>
    <link href="css/medbill.css" rel="stylesheet" type="text/css" />	
 	<link href="css/calendar-win2k-1.css" rel="stylesheet" type="text/css"/>  
	
	<script type="text/javascript" src="script/calendar.js"></script>
	<script type="text/javascript" src="script/calendar-en.js"></script>
	<script type="text/javascript" src="script/calendar-setup.js"></script>
  
    <title>PMS</title>
    <script language="javascript">
    function validateForm(){
    
	if(document.getElementById("from_date").value.length<=8){
		alert("Pleaes select service date ");
		document.getElementById("from_date").focus();
		return false;
	}
	if(document.getElementById("to_date").value.length<=8){
		alert("Pleaes select service date ");
		document.getElementById("to_date").focus();
		return false;
	}
	var diagCounter=0;
	var procCounter=0;	
	
	
		for(i=0 ; i<document.patient_diag.icd_code.length; i++)
		{	
			if(document.patient_diag.icd_code[i].checked){
				diagCounter++;
			}
			
		}
		
		if(diagCounter==0){
			alert("Please select at least one item from Diagnosis section.");
			return false;
		}else if(diagCounter > 4){
			alert("You can not select more then four items from Diagnosis section");
			return false;
		}
		
		for(i=0 ; i<document.patient_diag.cpt_code.length; i++)
		{		
			if(document.patient_diag.cpt_code[i].checked){
				selectedProc="true";
				procCounter++;
			}			
		}
		
		if(procCounter==0){
			if(document.patient_diag.others.checked){			
				//other options selected
			}else{
				alert("Please select at least one item from Procedures section.");
				return false;
			}
		}
		return true;
	}
	
	
	/*
	calender related code
	*/
	
  var input_field="";
  function showCalendar(id, format, showsTime, showsOtherMonths, inputField)
  {
		var calDate;
		input_field = inputField; 
		//	inputField = document.getElementById("strategicTaskCreate:completedOnDate").value;
		if (inputField.value.length>0)
			calDate = inputField.value;
		else
			calDate = null;
			
		var calTask = new Calendar(0, calDate, onSelectTaskPageCompDate, onCloseTaskPageCompDate);
		
		calTask.weekNumbers = false;
		calTask.showsTime = false;
		calTask.showsOtherMonths = false;
		calTask.isPopup = true;
		calTask.setDateFormat("%m/%d/%Y");
		calTask.create();	
		
		calTask.showAtElement(document.getElementById(id),"Br");	
		
	}
	function onSelectTaskPageCompDate(calendar, date)
	{
	 if(calendar.dateClicked)
	 {
	   //var input_field= document.getElementById("strategicTaskCreate:completedOnDate");
	   input_field.value = date;
		onCloseTaskPageCompDate(calendar);  
	 }
	}
	
	function onCloseTaskPageCompDate(cal)
	{
		cal.hide();
	}

    </script>
    </head>
    <body>
	<table width="860" height="100%" border="0" align="center" cellpadding="0" cellspacing="0">
  <tr>
    <td height="204" valign="top"><%@include file="header.jsp"%></td>
  </tr>
  <tr>
    <td height="30" bgcolor="#1f226f" class="headingBlue">Medical Billing and Claim Processing Professionals</td>
  </tr>
  <tr>
    <td valign="top" bgcolor="#ccae74"><table width="96%" border="0" align="center" cellpadding="0" cellspacing="0">
      <tr>
        <td><table width="100%" border="0" cellspacing="0" cellpadding="0">
          <tr>
            <td width="470" valign="top" class="txtPageTitle">Patient Form  </td>
            <td>&nbsp;</td>
          </tr>
        </table></td>
      </tr>
      <tr>
        <td><table width="100%" border="0" cellspacing="0" cellpadding="0">
          <tr>
            <td width="560"></td>
              </tr>
              <tr>
                <td class="txtHomeBody"></td>
              </tr>
            </table>
              <br>
        <form method="post" name="patient_diag" action="savePatientData.jsp" onsubmit="return validateForm();">
        <input type="hidden" name="patient_id" value="<%=pId%>"/>
            <input type="submit" value="Save" style="width:100px;"/> <input type="button" value="Cancel" style="width:100px;" onclick="location='home.jsp'"/>
            &nbsp;<br><br>
           <table cellpadding="0" cellspacing="0" width="100%">
                <tr>
                    <th colspan="4">&nbsp;Patient Information</th>
                </tr>
                <tr>
                    <td width="106">Patient ID:</td>
                    <td width="271">&nbsp;<%=pId %></td>
                    <td width="115">Patient Name:</td>
                    <td>&nbsp;<%=FirstName+" "+ LastName%></td>
                </tr>
                <tr>
                    <td width="106">DOB:</td>
                    <td width="271">&nbsp;<%=DOB%></td>
                    <td width="115">Home Phone:</td>
                    <td>&nbsp;<%=HomePhone%></td>
                </tr>
                <tr>
                    <td width="106">SSN:</td>
                    <td width="271">&nbsp;<%=SSN%></td>
                    <td width="115"></td>
                    <td>&nbsp;</td>
                </tr>
                <tr>
                    <td width="106">&nbsp;</td>
                    <td width="271">&nbsp;</td>
                    <td width="115">&nbsp;</td>
                    <td>&nbsp;</td>
                </tr>
            </table>
            <div id="patient_info"></div>
            <table cellpadding="0" cellspacing="0" width="100%">
                <tr>
                    <th>Billing Information:</th>
                </tr>
            </table>
            <table border="0" style="border-collapse: collapse">
				<tr>
					<td> Service Date:</td>
				<td>
				<table border="0" style="border-collapse: collapse">
					<tr>
						<td>From: </td>
						<td><input type="text" name="from_date" id="from_date" size="20" readonly="readonly"></td>
						<td><img src="images/cal-icon.gif" onClick="return showCalendar('btnCalendar', '%m/%d/%Y', '24', false, document.getElementById('from_date'));" id="btnCalendar" /></td>
						<td>&nbsp;To:</td>
						<td><input type="text" name="to_date" size="20" id="to_date" readonly="readonly"></td>
						<td><img src="images/cal-icon.gif" onClick="return showCalendar('btnCalendar1', '%m/%d/%Y', '24', false, document.getElementById('to_date'));" id="btnCalendar1"/></td>
						<td>(MM/DD/YYYY)</td>
					</tr>
				</table></td>
			</tr>
				<!--<tr>
					<td> Billing Cycle:</td>
				<td><input type="text" name="BillingCycle" size="20"></td>
			</tr>-->
		</table>
		<br>
            <table border="0" width="100%" style="border-collapse: collapse">
                <tr>
                    <th width="24"><p></th>
                    <th width="38">ICD</th>
                    <th>Diagnosis</th>
                    <th width="24"><p></th>
                    <th width="38">ICD</th>
                    <th>Diagnosis</th>
					<th width="24"><p></th>
                    <th width="38">ICD</th>
                    <th>Diagnosis</th>
					<th width="24"><p></th>
                    <th width="38">ICD</th>
                    <th>Diagnosis</th>                    
                </tr>
            <%
            
            String docCode= (String) session.getAttribute("Doc_Code");
            /*
            	selecting template if user is of doctor type
            */
            
            String query = "select * from tbldiag where active='Yes' order by code";
            
            if(docCode!=null){
            	query = "select Code, Description, ICDA from tbldiag diag, tblsuperbilltemplate_diag temp where diag.Code = temp.DiagCode and diag.Active='Yes' and temp.DocCode='"+docCode+"' order by diag.Code"; 
            }
            
            rs = s.executeQuery(query);
            while (rs.next()) {
            %>
                <tr>                
                    <td width="24"><input type="checkbox" name="icd_code" value="<%=rs.getString("Code")%>"/></td>
                    <td width="38"><%=rs.getString("ICDA")%></td>
                    <td><%=rs.getString("Description")%></td>                    
                    <%if(rs.next()){%>
                    	<td width="24"><input type="checkbox" name="icd_code" value="<%=rs.getString("Code")%>"/></td>
                   		 <td width="38"><%=rs.getString("ICDA")%></td>
                   		 <td><%=rs.getString("Description")%></td>
                    <%}else{%>
                    	<td width="24">&nbsp;</td>
                   		 <td width="38">&nbsp;</td>
                   		 <td>&nbsp;</td>
                    <%}%>
					<%if(rs.next()){%>
                    	<td width="24"><input type="checkbox" name="icd_code" value="<%=rs.getString("Code")%>"/></td>
                   		 <td width="38"><%=rs.getString("ICDA")%></td>
                   		 <td><%=rs.getString("Description")%></td>
                    <%}else{%>
                    	<td width="24">&nbsp;</td>
                   		 <td width="38">&nbsp;</td>
                   		 <td>&nbsp;</td>
                    <%}%>
										<%if(rs.next()){%>
                    	<td width="24"><input type="checkbox" name="icd_code" value="<%=rs.getString("Code")%>"/></td>
                   		 <td width="38"><%=rs.getString("ICDA")%></td>
                   		 <td><%=rs.getString("Description")%></td>
                    <%}else{%>
                    	<td width="24">&nbsp;</td>
                   		 <td width="38">&nbsp;</td>
                   		 <td>&nbsp;</td>
                    <%}%>                              
                </tr>
                <%
            }
                %>
            </table>
            <br>
            <table border="0" width="100%" style="border-collapse: collapse">
                <tr>
                    <th width="24">&nbsp;</th>
                    <th width="38">CPT</th>
                    <th>Procedures</th>
                    <th width="24">&nbsp;</th>
                    <th width="38">CPT</th>
                    <th>Procedures</th>
					<th width="24">&nbsp;</th>
                    <th width="38">CPT</th>
                    <th>Procedures</th>

                </tr>
           <%
           	/*
            	selecting template if user is of doctor type
           	*/
           
	        query = "select * from tblProcedure where active='Yes' order by description";
	        
            if(docCode!=null){
            	query = "select Code, Description, CPT from tblprocedure proc, tblsuperbilltemplate_proc temp where proc.Code = temp.ProcCode and proc.Active='Yes' and temp.DocCode='"+docCode+"' order by proc.Code"; 
            }
            	rs = s.executeQuery(query);
            	while (rs.next()) {
                %>
                <tr>
                    <td width="24"><input type="checkbox" name="cpt_code" value="<%=rs.getString("Code")%>"></td>
                    <td width="38"><%=rs.getString("CPT")%></td>
                    <td><%=rs.getString("Description")%></td>                    
                    <%
                    if(rs.next()){
                    %>
                    <td width="24"><input type="checkbox" name="cpt_code" value="<%=rs.getString("Code")%>"></td>
                    <td width="38"><%=rs.getString("CPT")%></td>
                    <td><%=rs.getString("Description")%></td>
                    <%
                    }else{
                    %>
	                  <td width="24">&nbsp;</td>
                   	  <td width="38">&nbsp;</td>
                   	  <td>&nbsp;</td>
                    <%
                    }
                    %>
					<%
                    if(rs.next()){
                    %>
                    <td width="24"><input type="checkbox" name="cpt_code" value="<%=rs.getString("Code")%>"></td>
                    <td width="38"><%=rs.getString("CPT")%></td>
                    <td><%=rs.getString("Description")%></td>
                    <%
                    }else{
                    %>
	                  <td width="24">&nbsp;</td>
                   	  <td width="38">&nbsp;</td>
                   	  <td>&nbsp;</td>
                    <%
                    }
                    %>
                </tr>
                <%
            		}
                %>
            </table>
            <p><b><input type="checkbox" name="others">Others:</b><br>
			<textarea rows="6" name="narration" cols="69"></textarea><br>
            <br>
            <input type="submit" value="Save" style="width:100px;"/> <input type="button" value="Cancel" style="width:100px;" onclick="location='home.jsp'"/>
        </p>
        </form>
		  <br></td>
            <td width="45" valign="top">&nbsp;</td>
            <td valign="top">&nbsp;</td>
          </tr>
        </table></td>
      </tr>
    </table></td>
  </tr>
  <tr>
    <td height="62" valign="top"><!-- #BeginLibraryItem "/Library/footer.lbi" --><table width="100%" border="0" cellspacing="0" cellpadding="0">
      <tr>
        <td height="4" bgcolor="#c7540f"></td>
      </tr>
      <tr>
        <td height="58" bgcolor="#1e2667">&nbsp;</td>
      </tr>
    </table><!-- #EndLibraryItem --></td>
  </tr>
</table>
    </body>
</html>
<%
            rs.close();
            s.close();
            c.close();
%>